package EntidadeFactory;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class EntityM {
	
	private EntityManager entityManager;
	private EntityManagerFactory factory;
	
	public EntityM() {
		factory = Persistence.createEntityManagerFactory("unitPSC");
		entityManager = factory.createEntityManager();
	}
	
	public void beginTransaction(){
		entityManager.getTransaction().begin();
	}
	
	public void commit(){
		entityManager.getTransaction().commit();
	}
	
	
	public void close(){
		entityManager.close();
		factory.close();
	}
	
	public void rollBack(){
		entityManager.getTransaction().rollback();
	}
	
	
	public void setEntityManager(EntityManager entityManager) {
		this.entityManager = entityManager;
	}

	public EntityManager getEntityManager() {
		return entityManager;
	}
	
	public EntityManagerFactory getEntityManagerFactory() {
		return factory;
	}
	

}
